package ch.sv7.tool.dbmanager.db.difference;

import ch.sv7.tool.dbmanager.db.ColumnSchema;
import ch.sv7.tool.dbmanager.db.TableSchema;

public class ExtraColumnDifference extends AbstractColumnDifference {

	private TableSchema expectedTableSchema;
	
	public ExtraColumnDifference(TableSchema expectedTableSchema, TableSchema actualTableSchema, ColumnSchema expectedColumnSchema, ColumnSchema actualColumnSchema) {
		super(expectedTableSchema, actualTableSchema, expectedColumnSchema, actualColumnSchema);
		this.expectedTableSchema = expectedTableSchema;
	}
	
	/**
	 * @return the expectedTableSchema
	 */
	public TableSchema getExpectedTableSchema() {
		return expectedTableSchema;
	}

	public String getMessage() {
		return 
		"Table [" + getTableName() 
		+ "] has extra column [" + getActualColumnSchema().getName() + "] "
		+ (getActualColumnSchema().getType().isNullable() ? "nullable": "non-nullable")
		+ ", " 
		+(getActualColumnSchema().getType().getDefaultValue() != null ? 
				"default value:  '" + getActualColumnSchema().getType().getDefaultValue() + "'" : "no default value");
	}
	
	public boolean isBlocker() {
		return (getActualColumnSchema().getType().isNullable() 
				|| (!getActualColumnSchema().getType().isNullable() 
					&& getActualColumnSchema().getType().getDefaultValue() != null))
				? false : true;
	}
}
